package com.dingding.dao.systemdao.impl;

import java.util.Date;
import java.util.List;

import com.dingding.bean.databean.response.ResCheckUpdate;
import com.dingding.common.core.beans.Activity;
import com.dingding.common.core.util.ToolUtil;
import com.dingding.dao.basedao.impl.BaseDaoImpl;
import com.dingding.dao.sql.SystemNewsServiceSQL;
import com.dingding.dao.systemdao.ISystemNewsDao;

public class SystemNewsDaoImpl extends BaseDaoImpl<Activity> implements ISystemNewsDao {

	/**
	 * 获取版本更新信息bean
	 */
	@Override
	public ResCheckUpdate getUpdateInfo(Integer deviceType) {

		ResCheckUpdate resCheckUpdate = new ResCheckUpdate();
		List<Object[]> objects = null;

		try {

			objects = sqlQueryListObj(SystemNewsServiceSQL.GET_UPDATE_INFO, false, deviceType);
		} catch (Exception e) {
			log.error("获取版本更新内容异常," + this.getClass() + "getUpdateInfo()");
		}

		if (objects == null || objects.size() <= 0) {
			// 查无数据
			return null;
		}

		this.convertBean(objects.get(0), resCheckUpdate);

		return resCheckUpdate;
	}

	/**
	 * @Title: convertBean
	 * @Description: 转换响应检查更新bean
	 * @param obj
	 * @param resCheckUpdate
	 * @author lijinchao
	 * @return void
	 * @throws
	 */
	private void convertBean(Object[] obj, ResCheckUpdate resCheckUpdate) {

		// 最新版本
		if (obj[0] != null) {
			resCheckUpdate.setAppVersion(obj[0].toString());
		}
		// 最新版本号
		if (obj[1] != null) {
			resCheckUpdate.setAppVersionCode(ToolUtil.castInteger(obj[1]));
		}
		// 最低版本
		if (obj[2] != null) {
			resCheckUpdate.setMinVersion(obj[2].toString());
		}
		// 最新版本号
		if (obj[3] != null) {
			resCheckUpdate.setMinVersionCode(ToolUtil.castInteger(obj[3]));
		}
		// 下载地址
		if (obj[4] != null) {
			resCheckUpdate.setUrl(obj[4].toString());
		}
		// 更新时间
		if (obj[5] != null) {
			resCheckUpdate.setCreateTime((Date) obj[5]);
		}
		// 更新内容
		if (obj[6] != null) {
			resCheckUpdate.setDescription(obj[6].toString());
		}
	}

}
